package com.gome.boot.config.webservice.extension.auth;

import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transport.http.HTTPConduitConfigurer;

/**
 * HTTP访问认证通道配置器.
 *
 * @author baoxiufeng
 */
public class AuthHTTPConduitConfigurer implements HTTPConduitConfigurer {

    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;

    /**
     * 构造方法.
     *
     * @param username 用户名
     * @param password 密码
     */
    public AuthHTTPConduitConfigurer(String username, String password) {
        this.username = username;
        this.password = password;
    }

    @Override
    public void configure(String name, String address, HTTPConduit httpConduit) {
        AuthorizationPolicy authorizationPolicy = new AuthorizationPolicy();
        authorizationPolicy.setUserName(username);
        authorizationPolicy.setPassword(password);
        authorizationPolicy.setAuthorizationType("Basic");
        httpConduit.setAuthorization(authorizationPolicy);
    }
}
